package com.kt.NetworkModel

import android.app.Application
import android.content.Context
import android.graphics.Color
import androidx.annotation.NonNull
import androidx.core.content.ContextCompat
import com.blankj.utilcode.util.Utils
import com.kt.ktmvvm.lib.R
import com.scwang.smartrefresh.layout.SmartRefreshLayout
import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreator
import com.scwang.smartrefresh.layout.api.RefreshHeader
import com.scwang.smartrefresh.layout.api.RefreshLayout
import com.scwang.smartrefresh.layout.header.ClassicsHeader
import com.tencent.mmkv.MMKV
import com.tencent.navix.api.NavigatorConfig
import com.tencent.navix.api.NavigatorZygote
import com.tencent.tencentmap.mapsdk.maps.TencentMapInitializer
import me.jessyan.autosize.AutoSize
import me.jessyan.autosize.AutoSizeConfig
import me.jessyan.autosize.unit.Subunits

/**
 * @author 浩楠
 *
 * @date 2023/1/9   18:00.
 *
 *      _              _           _     _   ____  _             _ _
 *     / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 *    / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 *   / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 *  /_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 * 描述:
 */
class App : Application() {

    init {
        //设置全局的Header构建器
        SmartRefreshLayout.setDefaultRefreshHeaderCreator(object : DefaultRefreshHeaderCreator {
            override fun createRefreshHeader(context: Context, layout: RefreshLayout): RefreshHeader {
                layout.setHeaderHeightPx(180);
                ClassicsHeader.REFRESH_HEADER_REFRESHING = "为你加载中...";
                ClassicsHeader.REFRESH_HEADER_FINISH = "加载完成";
                return ClassicsHeader(context).setTextSizeTime(12f).setTextSizeTitle(12f).setPrimaryColor(Color.parseColor("#F6F5F5"))

            }
        });
    }

    override fun onCreate() {
        super.onCreate()
        instance = this
        AutoSize.initCompatMultiProcess(this);
        AutoSize.checkAndInit(this);
        AutoSizeConfig.getInstance().setCustomFragment(true).setExcludeFontScale(true)
            .setPrivateFontScale(0.8f).setLog(false).setBaseOnWidth(true).setUseDeviceSize(true)
            .getUnitsManager().setSupportDP(true).setDesignSize(2160F, 3840F).setSupportSP(true)
            .setSupportSubunits(Subunits.MM)
        MMKV.initialize(this)
        Utils.init(this)
        // 设置同意地图SDK隐私协议
        TencentMapInitializer.setAgreePrivacy(applicationContext, true)
        // 初始化导航SDK
        NavigatorZygote.with(applicationContext).init(
            NavigatorConfig.builder() // 设置同意导航SDK隐私协议
                .setUserAgreedPrivacy(true) // 设置自定义的可区分设备的ID
                .setDeviceId("develop_custom_id_123456")
                .build()
        )
    }

    /*
     * 更换王漢宗勘亭流繁
     */
    open fun changeTTF() {
//        ChangeDefaultFontUtils.setDefaultFont(this, "SERIF", "fonts/wangmozongkantingliufan.ttf");
    }

    companion object {
        private var instance: Application? = null
        fun get(): App {
            return instance as App
        }

    }
}